﻿Imports System.ComponentModel
Imports Aricie.DNN.UI.WebControls.EditControls
Imports DotNetNuke.UI.WebControls
Imports Aricie.DNN.UI.Attributes

Namespace Aricie.DNN.Modules.LuceneSearch.Settings

    Public Class AutoComplete

        Private Const HeaderTemplateDefault As String = "<div style=""color: silver;"">Search results</div>"
        Private Const CategoryTemplateDefault As String = "<div style=""text-align: center; font-weight: bolder""><#= ItemType #></div>"
        Private Const ItemTemplateDefault As String = "<#=Description#>"
        Private Const NoAnswerTemplate As String = "No results"
        Public Const CustomPositionDefault As String = "{ ""my"": ""left top"", ""at"": ""left bottom"", ""collision"": ""none"" }"
        Public Const CustomOpeningWindowTemplateDefault As String = "return null;"


        Public Property EnableAutoComplete As Boolean = False

#Region "Paramètres serveur"

        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Server")> _
        Public Property CharsForCompletion As Integer = 2
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Server")> _
        Public Property ReturnSetSize As Integer = 10


        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Editor(GetType(ListEditControl), GetType(EditControl))> _
        <CollectionEditor(DisplayStyle:=CollectionDisplayStyle.List, showAddItem:=True, ItemsReadOnly:=True, Ordered:=False)> _
        <InnerEditor(GetType(SelectorEditControl), GetType(AutoCompleteSettings.OutputFieldsInnerAttributes))> _
        <Category("Server")> _
        <LabelMode(LabelMode.Top)> _
        Public Property OutputFields As New List(Of String)
    
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Server")> _
        <LabelMode(LabelMode.Top)> _
        <CollectionEditor(False, True, False, True, 10, CollectionDisplayStyle.Accordion, False)> _
        Public Property SortingFields As New List(Of AutoCompleteSettings.SortingField)

#End Region

#Region "Paramètres client"
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <AutoPostBack()> _
        <Category("Client")> _
        Public Property EnableCustomPosition As Boolean = False
        <ConditionalVisible("DisplayPosition", False, True)> _
        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <Category("Client")> _
        Public Property CustomPosition As String = CustomPositionDefault

        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <AutoPostBack()> _
        <Category("Client")> _
        Public Property EnableHeader As Boolean = False
        <ConditionalVisible("DisplayHeader", False, True)> _
        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <Category("Client")> _
        Public Property HeaderText As String = HeaderTemplateDefault


        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <AutoPostBack()> _
        <Category("Client")> _
        Public Property EnableGrouping As Boolean = False
        <ConditionalVisible("DisplayGroupName", False, True)> _
        <Editor(GetType(SelectorEditControl), GetType(EditControl))> _
        <Selector(GetType(AutoCompleteSettings.SortingFieldsSelector), "Id", "Id", True, False, "", "", False, False)> _
        <Category("Client")> _
        Public Property GroupName As String = String.Empty
        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <ConditionalVisible("DisplayGroupName", False, True)> _
        <Category("Client")> _
        Public Property CategoryTemplate As String = CategoryTemplateDefault

        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Client")> _
        Public Property ItemTemplate As String = ItemTemplateDefault
        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Client")> _
        Public Property NoAnswer As String = NoAnswerTemplate

        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Client")> _
        Public Property EnableHighlights As Boolean = False

        <Editor(GetType(CustomTextEditControl), GetType(EditControl)), LineCount(3), Width(400)> _
        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <Category("Client")> _
        Public Property OpenInNewWindow As String = CustomOpeningWindowTemplateDefault

        <ConditionalVisible("EnableAutoComplete", False, True)> _
        <AutoPostBack()> _
        <Category("Client")> _
        Public Property IncludeScriptAndStyle As Boolean = True
        <ConditionalVisible("DisplayScriptReplacement", False, True)> _
        <Category("Client")> _
        <Width(400)> _
        Public Property jQueryJSUrl As String = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
        <ConditionalVisible("DisplayScriptReplacement", False, True)> _
        <Category("Client")> _
        <Width(400)> _
        Public Property jQueryUIJSUrl As String = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"
        <ConditionalVisible("DisplayScriptReplacement", False, True)> _
        <Category("Client")> _
        Public Property CrushJQueryUI As Boolean = False
        <ConditionalVisible("DisplayScriptReplacement", False, True)> _
        <Category("Client")> _
        <Width(400)> _
        Public Property jQueryUICSSUrl As String = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css"

#End Region

#Region "Combinatoire d'affichage"
        <Browsable(False)> _
        Public ReadOnly Property DisplayHeader As Boolean
            Get
                Return EnableAutoComplete AndAlso EnableHeader
            End Get
        End Property

        <Browsable(False)> _
        Public ReadOnly Property DisplayGroupName As Boolean
            Get
                Return EnableAutoComplete AndAlso EnableGrouping
            End Get
        End Property

        <Browsable(False)> _
        Public ReadOnly Property DisplayScriptReplacement As Boolean
            Get
                Return EnableAutoComplete AndAlso IncludeScriptAndStyle
            End Get
        End Property

        <Browsable(False)> _
        Public ReadOnly Property DisplayPosition As Boolean
            Get
                Return EnableAutoComplete AndAlso EnableCustomPosition
            End Get
        End Property

#End Region

    End Class

End Namespace